﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using System.Configuration;

public partial class Page_NewsDetail : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TinTuc tt = TTBLL.LayTheoMa(int.Parse(Request.QueryString["Id"]));
        LoadTinMoi(tt.ThoiDiem);
        LoadTinCu(tt.ThoiDiem);
    }
    protected void FormView1_DataBound(object sender, EventArgs e)
    {
        TaiKhoan TK = (TaiKhoan)Session["TaiKhoan"];
        if (TK != null && TK.MaNhomQuyen == 1)
        {
            FormView1.FindControl("hplEdit").Visible = true;
        }
    }

    void LoadTinMoi(DateTime dt)
    {
        List<TinTuc> dst = TTBLL.LayTinMoi(int.Parse(ConfigurationManager.AppSettings["SoTinMoiCuMoi"]), dt);
        if (dst.Count > 0)
        {
            tbTinMoi.Visible=true;
            string str = TaoLinkTin(dst);

            tdTinMoi.InnerHtml = str;
        }
    }

    void LoadTinCu(DateTime dt)
    {
        List<TinTuc> dst = TTBLL.LayTinCu(int.Parse(ConfigurationManager.AppSettings["SoTinMoiCuMoi"]), dt);
        if (dst.Count > 0)
        {
            tbTinCu.Visible = true;
            string str = TaoLinkTin(dst);

            tdTinCu.InnerHtml = str;
        }
    }

    private static string TaoLinkTin(List<TinTuc> dst)
    {
        string str = "<ul class=\"ulnewolditem\">";
        foreach (TinTuc tt in dst)
        {
            str += "<li> <a class=\"nonunderlink\" href=\"Page_NewsDetail.aspx?Id=" + tt.Ma + "\">" + tt.TieuDe + "</a></li>";
        }
        str += "</ul>";
        return str;
    }

    protected void FormView1_DataBinding(object sender, EventArgs e)
    {

    }
}
